package com.atguigu.springcloud.constant;

import org.springframework.lang.Nullable;

/**
 * Created by luojie on 2018/9/6.
 */
public enum BusinessStatus {

    NOT_SUPPORT_FILE_TYPE(100007, "不支持的文件类型"),

    TOKEN_ERROR(100004, "TOKEN错误");

    private final int value;

    private final String reasonPhrase;

    BusinessStatus(int value, String reasonPhrase) {
        this.value = value;
        this.reasonPhrase = reasonPhrase;
    }

    public int value() {
        return this.value;
    }

    public String getReasonPhrase() {
        return this.reasonPhrase;
    }

    @Override
    public String toString() {
        return Integer.toString(this.value);
    }

    public static BusinessStatus valueOf(int statusCode) {
        BusinessStatus status = resolve(statusCode);
        if (status == null) {
            throw new IllegalArgumentException("No matching constant for [" + statusCode + "]");
        }
        return status;
    }

    @Nullable
    public static BusinessStatus resolve(int statusCode) {
        for (BusinessStatus status : values()) {
            if (status.value == statusCode) {
                return status;
            }
        }
        return null;
    }
}
